package com.jiangdong.craft.controller;

import com.jiangdong.craft.service.CraftService;
import com.jiangdong.craft.dto.ResponseDTO;
import com.jiangdong.craft.entity.Craft;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/craft")
@CrossOrigin
public class CraftController {

    @Autowired
    private CraftService craftService;

    @PostMapping("/add")
    public ResponseDTO add(Craft craft){
        return craftService.add(craft);
    }

    @PostMapping("/del")
    public ResponseDTO delById(@RequestParam("id") Integer id){
        return craftService.delById(id);
    }

    /**
     * @param id 概要信息id
     * @param isProcedure 是否返回关联节点信息  0:不返回 1:返回
     * @return
     */
    @GetMapping("/query")
    public ResponseDTO<Craft> queryById(@RequestParam("id")Integer id,
                                        @RequestParam("isProcedure") Integer isProcedure){
        return craftService.queryById(id,isProcedure);
    }

    /**
     * @param p 当前页码数 不传默认为第一页
     * @param pageSize 每页显示数量 不传默认10
     * @param keyWord 关键词
     * @param createTime 创建时间 格式为20190314
     * @return
     */
    @GetMapping("/query/comprehensiveQuery")
    public ResponseDTO<List<Craft>> comprehensiveQuery(@RequestParam(value = "p",defaultValue = "1",required = false)Integer p,
                                                       @RequestParam(value = "pageSize",defaultValue = "10",required = false)Integer pageSize,
                                                       @RequestParam(value = "keyWord",required = false)String keyWord,
                                                       @RequestParam(value = "createTime",required = false)String createTime){
       return craftService.comprehensiveQuery(p,pageSize,keyWord,createTime);
    }
}
